﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;
using DevComponents.DotNetBar.Controls;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmQuanLyTaiKhoan : DevComponents.DotNetBar.Office2007Form
    {
        public frmQuanLyTaiKhoan()
        {
            InitializeComponent();
        }
        private void frmQuanLyTaiKhoan_Load(object sender, EventArgs e)
        {
            tabAll_Click(null, null);
            XuLyDataGridView.dgrMouseMove(dgrDanhSach);
            XuLyDataGridView.Style(dgrDanhSach);
        }

        private void tabAll_Click(object sender, EventArgs e)
        {
            TabConTrol.SelectedTab = tabAll;
            dgrDanhSach.Columns.Clear();
            dgrDanhSach.DataSource = TaiKhoan_Info.GetAll().Tables[0];
            XuLyDataGridView.AddCotButtom(dgrDanhSach, "Xóa");
            TabConTrol.Height = 26;
        }
        private void tabTimKiem_Click(object sender, EventArgs e)
        {
            TabConTrol.Height = 100;
            cbChoose.SelectedIndex = 0;

        }
        private void dgrDanhSach_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (tabNhanVien.IsSelected || tabTimKiem.IsSelected || tabThem.IsSelected)
            {
                try
                {
                    if (TaiKhoan_Info.GetByID(dgrDanhSach.CurrentRow.Cells["manv"].Value.ToString()).Count == 0)
                    {
                        TabConTrol.SelectedTab = tabThem;
                        txtMaNV.Text = txtMatKhau.Text = dgrDanhSach.CurrentRow.Cells["manv"].Value.ToString();
                        tabThem.Visible = true;
                        TabConTrol.Height = 75;
                        TabConTrol.SelectedTab = tabThem;
                    }
                    else
                    {
                        TabConTrol.SelectedTab = tabNhanVien;
                        tabNhanVien_Click(null, null);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
        //private void btnXoa_Click(object sender, EventArgs e)
        //{
        //    if (ThietBi_info.Delete(txtMaNV.Text))
        //    {
        //        BatLoi.ThongBao("Xóa Thiết Bị Thành Công");
        //        tabAll_Click(null, null);
        //    }

        //}
        //private void btnXoaSelectItem_Click(object sender, EventArgs e)
        //{
        //    if (BatLoi.DgResult("Bạn có muốn xóa những thiết bị được chọn"))
        //        foreach (DataGridViewRow r in dgrDanhSach.SelectedRows)
        //            ThietBi_info.Delete(r.Cells["matb"].Value.ToString());
        //}


        private void tabNhanVien_Click(object sender, EventArgs e)
        {
            dgrDanhSach.Columns.Clear();
            dgrDanhSach.DataSource = NhanVien_Info.All();
            tabThem.Visible = false;
            TabConTrol.Height = 26;
        }

        private void dgrDanhSach_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (tabAll.IsSelected)
                try
                {
                    frmThongTinNhanVien f = new frmThongTinNhanVien(NhanVien_Info.GetByID(dgrDanhSach.CurrentRow.Cells["MÃ NHÂN VIÊN"].Value.ToString())[0]);
                    f.ShowDialog();
                }
                catch (Exception)
                {
                }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            switch (cbChoose.SelectedIndex)
            {
                case 0:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByName(txtSearch.Text);
                    break;
                case 1:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByID(txtSearch.Text);
                    break;
                case 2:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByCMND(txtSearch.Text);
                    break;
            }
        }
    }
}
